package ch.unisi.inf.java.project.riskbami.view;

import ch.unisi.inf.java.project.riskbami.model.*;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.*;
import javax.swing.UIManager;

/**
 * The little frame that comes before the setup frame for the game. It contains 3 buttons
 * One to bring the player to the setupFrame and let him play.
 * One to read about the game.
 * One to quit the application.
 * 
 * @author minellir@lu.unisi.ch
 * @author babazadm@lu.unisi.ch
 */
public final class PreRiskFrame extends JFrame
{

    /**
     * Constructor for the clas PreRiskFrame. Construct the frame and set the buttons.
     */
    public PreRiskFrame() {
        try {
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); //UIManager.getCrossPlatformLookAndFeelClassName());
            } catch (final Exception e) {
                e.printStackTrace();
            }
        final JFrame frame = new JFrame("RiskBaMi - The Java version of Risk");
        frame.setSize(550, 450);
        frame.setResizable(false);
        final Container contentPane = frame.getContentPane();
        contentPane.setLayout(new BorderLayout());
        
        //New panel added to the window
        final JPanel centralPanel = new JPanel();
        GridLayout my = new GridLayout(3, 0);
        my.setVgap(25);
        centralPanel.setLayout(my);
        contentPane.add(centralPanel, BorderLayout.CENTER);
        
        //New label for the top image
        final JPanel topImagePanel = new JPanel();
        final JLabel topImage = new JLabel(new ImageIcon(getClass().getResource("images/RiskBaMiLogo.png")));
        topImagePanel.add(topImage);
        contentPane.add(topImagePanel, BorderLayout.NORTH);
        
        
        //Buttons
        final JButton startGame = new JButton("Start Game");
        startGame.addActionListener(new StartGameListener(frame));
        final JButton about = new JButton ("About BaMiRisK");
        about.addActionListener(new ActionListener (){
            public void actionPerformed (final ActionEvent ev){
                JOptionPane.showMessageDialog(frame,
                    "RiskBaMi powered by Masiar Babazadeh and Roberto Minelli\n",
                    "About BaMiRisk",
                    JOptionPane.INFORMATION_MESSAGE);
            }
        });
        final JButton quit = new JButton("Quit");
        quit.addActionListener(new ActionListener (){
            public void actionPerformed (final ActionEvent ev){
                System.exit(0);
            }
        });
        
        //Put buttons on the frame
        centralPanel.add(startGame, BorderLayout.CENTER);
        centralPanel.add(about, BorderLayout.CENTER);
        centralPanel.add(quit, BorderLayout.CENTER);
        
        //Make it visible
        //frame.pack();
        frame.setVisible(true);
        frame.setResizable(true);
        
    }
    
    //Classes to handle the buttons
    
    /**
     * StartGameListener listens when the player clicks the Start Game button.
     */
    private final class StartGameListener implements ActionListener{
        private JFrame frame;
        
            private StartGameListener(final JFrame frame){
                this.frame = frame;
            }
            
            public final void actionPerformed(final ActionEvent e) {
                SetupFrame setup = new SetupFrame();
                frame.setVisible(false);
            }
        }
}
